package site.kexing.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import site.kexing.mapper.LoginMapper;
import site.kexing.mapper.Product_OrderMapper;
import site.kexing.pojo.User;

import javax.servlet.http.HttpSession;

@Controller
public class LoginController {
    @Autowired
    private LoginMapper loginMapper;


    @RequestMapping("/checklogin")
    public String checkLogin(User user, HttpSession session, Model model){
        String s = loginMapper.checkLogin(user);
        if(s != null){
            session.setAttribute("user",user);
            return "index";
        }
        return "login";
    }

    @RequestMapping("/deletesession")
    public String deleteSession(HttpSession session){
        if (session.getAttribute("user") != null) {
            session.removeAttribute("user");
        }
        return "redirect:/login";
    }
}
